package com.scs.application.modules.base.controller;/**
 * @Description:
 */

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Maps;
import com.scs.application.core.model.CommonResult;
import com.scs.application.core.mvc.controller.BaseController;
import com.scs.application.core.utils.DateUtils;
import com.scs.application.core.utils.StringUtils;
import com.scs.application.core.utils.UserUtils;
import com.scs.application.modules.base.dto.CountInfoDTO;
import com.scs.application.modules.base.dto.TaskTodoDTO;
import com.scs.application.modules.base.entity.*;
import com.scs.application.modules.base.request.HospitalMaterialQueryRequest;
import com.scs.application.modules.base.request.ManufacturerQueryRequest;
import com.scs.application.modules.base.service.*;
import com.scs.application.modules.cert.entity.CertificateRepository;
import com.scs.application.modules.cert.service.CertificateRepositoryService;
import com.scs.application.modules.order.consts.DictConsts;
import com.scs.application.modules.order.entity.Delivery;
import com.scs.application.modules.order.entity.PurchaseOrder;
import com.scs.application.modules.order.service.DeliveryService;
import com.scs.application.modules.order.service.PurchaseOrderService;
import com.scs.application.modules.settlement.entity.Invoice;
import com.scs.application.modules.settlement.service.InvoiceService;
import com.scs.application.modules.upms.entity.User;
import com.scs.application.modules.upms.service.UserService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName WorkbenchController
 * @Description TODO
 */
@RequestMapping("/base/workbench")
@AllArgsConstructor
@RestController
public class WorkbenchController extends BaseController {

    private HospitalSupplierService hospitalSupplierService;

    private HospitalMaterialService hospitalMaterialService;

    private ManufacturerService manufacturerService;

    private PurchaseOrderService purchaseOrderService;

    private DeliveryService deliveryService;
    private CertificateRepositoryService certificateRepositoryService;
    private InvoiceService invoiceService;
    private UserService userService;
    private MaterialApplicantService materialApplicantService;
    private SupplierApplicantService supplierApplicantService;


    /**
     * 供应商工作台 基础数据 所供货的医疗机构的数量/供货品规的数量/供货产品生产厂商的数量
     *
     * @return
     */
    @GetMapping("/count_for_supplier")
    public CommonResult countForSupplier() {
        HashMap<String, Integer> map = Maps.newHashMapWithExpectedSize(3);
        //获取本月第一天0点
        String beginGmtCreate = DateUtils.format(DateUtils.getFirstDayOfMonth(new Date()), "yyyy-MM-dd 00:00:00");

        // 所供货的医疗机构的数量
        int hospitalCnt = hospitalSupplierService.count(Wrappers.<HospitalSupplier>query()
                .eq("supplier_id", UserUtils.getSupplierId())
                .eq("inactive", HospitalSupplier.ENABLE));
        map.put("hospitalCnt", hospitalCnt);

        //本月新增医疗机构数量
        int hospitalCntLast = hospitalSupplierService.count(Wrappers.<HospitalSupplier>query()
                .eq("supplier_id", UserUtils.getSupplierId())
                .eq("inactive", HospitalSupplier.ENABLE)
                .between("gmt_create", beginGmtCreate,new Date())
        );
        map.put("hospitalCntLast", hospitalCntLast);

        // 供货品规的数量
        //int materialSpecCnt = hospitalMaterialService.countForSupplier(new HospitalMaterialQueryRequest());
        List<HospitalMaterial> materialSpecCnt = hospitalMaterialService.list(new HospitalMaterialQueryRequest().setSupplierId(UserUtils.getSupplierId()));
        map.put("materialSpecCnt", materialSpecCnt.size());

        //本月新增
        // int materialSpecCntLast = hospitalMaterialService.countForSupplier(new HospitalMaterialQueryRequest().setBeginGmtCreate(DateUtils.parse(beginGmtCreate)).setEndGmtCreate(new Date()));
        List<HospitalMaterial> materialSpecCntLast = hospitalMaterialService.list(new HospitalMaterialQueryRequest().setSupplierId(UserUtils.getSupplierId()).setBeginGmtCreate(DateUtils.parse(beginGmtCreate)).setEndGmtCreate(new Date()));
        map.put("materialSpecCntLast", materialSpecCntLast.size());

        // 供货产品生产厂商的数量
        int manufacturerCnt = manufacturerService.count(Wrappers.<Manufacturer>query().eq("supplier_id", UserUtils.getSupplierId())
        );
        map.put("manufacturerCnt", manufacturerCnt);

        //本月新增厂商的数量
        int manufacturerCntLast = manufacturerService.count(Wrappers.<Manufacturer>query().eq("supplier_id", UserUtils.getSupplierId())
                .between("gmt_create", beginGmtCreate,new Date())
        );
        map.put("manufacturerCntLast", manufacturerCntLast);

        return CommonResult.ok("查询成功", map);

    }

    /**
     * 医院工作台 基础数据 供货商数量/所使用耗材品规的数量/供货产品生产厂商的数量
     *
     * @return
     */
    @GetMapping("/count_for_hospital")
    public CommonResult countForHospital() {
        HospitalMaterialQueryRequest request = new HospitalMaterialQueryRequest();
        HashMap<String, Integer> map = Maps.newHashMapWithExpectedSize(3);
        //获取本月第一天0点
        String beginGmtCreate = DateUtils.format(DateUtils.getFirstDayOfMonth(new Date()), "yyyy-MM-dd 00:00:00");
        // 供货商数量
        int supplierCnt = hospitalSupplierService.count(Wrappers.<HospitalSupplier>query()
                .eq("hospital_id", UserUtils.getHospitalId())
                .eq("inactive", HospitalSupplier.ENABLE));
        map.put("supplierCnt", supplierCnt);

        //本月新增供货商数量
        int supplierCntLast = hospitalSupplierService.count(Wrappers.<HospitalSupplier>query()
                .eq("hospital_id", UserUtils.getHospitalId())
                .eq("inactive", HospitalSupplier.ENABLE)
                .between("gmt_create", beginGmtCreate,new Date())
        );
        map.put("supplierCntLast", supplierCntLast);
        // 所使用耗材的数量
        List<HospitalMaterial> materialCnt = hospitalMaterialService.list(request.setHospitalId(UserUtils.getHospitalId()));
        /*int materialCnt = hospitalMaterialService.count(Wrappers.<HospitalMaterial>query()
                .eq("hospital_id", UserUtils.getHospitalId())
                .eq("inactive", HospitalMaterial.ACTIVATE)
        );*/
        map.put("materialCnt", materialCnt.size());
        //本月新增
        /*int materialCntLast = hospitalMaterialService.count(Wrappers.<HospitalMaterial>query()
                .eq("hospital_id", UserUtils.getHospitalId())
                .eq("inactive", HospitalMaterial.ACTIVATE)
                .between("gmt_create",beginGmtCreate,new Date())
        );*/
        List<HospitalMaterial> materialCntLast = hospitalMaterialService.list(request.setHospitalId(UserUtils.getHospitalId())
                .setBeginGmtCreate(DateUtils.parse(beginGmtCreate))
                .setEndGmtCreate(new Date())
        );
        map.put("materialCntLast", materialCntLast.size());

        // 供货产品生产厂商的数量
        int manufacturerCnt = manufacturerService.countForHospital(new ManufacturerQueryRequest());
        map.put("manufacturerCnt", manufacturerCnt);
        //本月新增厂商的数量
        int manufacturerCntLast = manufacturerService.countForHospital(new ManufacturerQueryRequest().setBeginGmtCreate(DateUtils.parse(beginGmtCreate)).setEndGmtCreate(new Date()));
        map.put("manufacturerCntLast", manufacturerCntLast);
        return CommonResult.ok("查询成功", map);
    }



    /**
     * 工作台基础数据统计
     *
     * @return
     */
    @GetMapping("/getCountInfoBase")
    public CommonResult getCountInfoBase() {
        Map<String,CountInfoDTO> data = new HashMap<>();
        QueryWrapper queryWrapper;
        CountInfoDTO countInfo;
        //获取本月第一天0点
        String dateBegin = DateUtils.format(DateUtils.getFirstDayOfMonth(new Date()), "yyyy-MM-dd") + " 00:00:00";
        String dateEnd = DateUtils.format(DateUtils.getLastDayOfMonth(new Date()), "yyyy-MM-dd"+ " 23:59:59");
        boolean isAll = UserUtils.isAdmin();
        boolean isSupplier = false;
        boolean isHospital = false;
        String hospitalId="";
        String supplierId="";
        String extra ="全部数据";
        if (!isAll) {
            try {
                isSupplier = UserUtils.isSupplier();
                supplierId = UserUtils.getSupplierId();
            }catch (Exception e) {
            }
            try {
                isHospital = UserUtils.isHospital();
                hospitalId = UserUtils.getHospitalId();
            }catch (Exception e) {
            }
            if (isHospital) {
                extra ="所属当前医院";
            }
            if (isSupplier) {
                extra ="所属当前供应商";
            }
        }


        // 非供应商时显示
        if (!isSupplier) {
            //供应商数量
            countInfo = new CountInfoDTO(0);
            queryWrapper = Wrappers.<HospitalSupplier>query().eq("inactive", HospitalSupplier.ENABLE);
            if (isHospital) {
                queryWrapper.eq(!isAll,"hospital_id", hospitalId);
            }
            countInfo.setShow(1).setExtra(extra).setValue( hospitalSupplierService.count(queryWrapper));
            data.put("spCount", countInfo);


            //本月增加供应商数量
            countInfo = new CountInfoDTO(0);
            queryWrapper = Wrappers.<HospitalSupplier>query().eq("inactive", HospitalSupplier.ENABLE).between("gmt_create", dateBegin,dateEnd);
            if (isHospital) {
                queryWrapper.eq(!isAll,"hospital_id", hospitalId);
            }
            countInfo.setShow(1).setExtra(extra).setValue( hospitalSupplierService.count(queryWrapper));
            data.put("spCountAdd", countInfo);
        }

        //商品数量
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<HospitalMaterial>query();
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        countInfo.setExtra(extra).setShow(1) .setValue( hospitalMaterialService.count(queryWrapper));
        if (isSupplier) {
            //countInfo.setWidth("40%");
        }
        data.put("matrCount", countInfo);

        //本月增加商品
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<HospitalMaterial>query();
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        queryWrapper.between("gmt_create", dateBegin,dateEnd);
        countInfo.setExtra(extra).setShow(1) .setValue( hospitalMaterialService.count(queryWrapper));
        if (isSupplier) {
            //countInfo.setWidth("40%");
        }
        data.put("matrCountAdd", countInfo);

        //生产厂家
        countInfo = new CountInfoDTO(0);
        ManufacturerQueryRequest manufacturerQueryRequest = new ManufacturerQueryRequest();
        manufacturerQueryRequest.setHospitalId(hospitalId).setGetHospitalIdByParam(true).setSupplierId(supplierId);
        countInfo.setExtra(extra).setShow(1).setValue( manufacturerService.countForHospital(manufacturerQueryRequest));
        if (isSupplier) {
            //countInfo.setWidth("40%");
        }
        data.put("mfgCount", countInfo);

        //本月增加生产厂家
        countInfo = new CountInfoDTO(0);
        manufacturerQueryRequest.setBeginGmtCreate(DateUtils.parse(dateBegin)).setEndGmtCreate(new Date()).setSupplierId(supplierId);
        countInfo.setExtra(extra).setShow(1) .setValue( manufacturerService.countForHospital(manufacturerQueryRequest));
        if (isSupplier) {
            //countInfo.setWidth("40%");
        }
        data.put("mfgCountAdd", countInfo);

        return CommonResult.ok("查询成功", data);
    }



    /**
     * 工作台业务统计
     *
     * @return
     */
    @GetMapping("/getCountInfoBus")
    public CommonResult getCountInfoBus() {
        Map<String,CountInfoDTO> data = new HashMap<>();
        QueryWrapper queryWrapper;
        CountInfoDTO countInfo;
        //获取本月第一天0点
        String dateBegin = DateUtils.format(DateUtils.getFirstDayOfMonth(new Date()), "yyyy-MM-dd") + " 00:00:00";
        String dateEnd = DateUtils.format(DateUtils.getLastDayOfMonth(new Date()), "yyyy-MM-dd"+ " 23:59:59");
        boolean isAll = UserUtils.isAdmin();
        boolean isSupplier = false;
        boolean isHospital = false;
        String hospitalId="";
        String supplierId="";
        String extra ="全部数据";
        if (!isAll) {
            try {
                isSupplier = UserUtils.isSupplier();
                hospitalId= UserUtils.getHospitalId();
            }catch (Exception e) {
            }
            try {
                isHospital = UserUtils.isHospital();
                supplierId = UserUtils.getSupplierId();
            }catch (Exception e) {
            }
            if (isHospital) {
                extra ="所属当前医院";
            }
            if (isSupplier) {
                extra ="所属当前供应商";
            }
        }

        //订单待确认
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<PurchaseOrder>query()
                .eq("ifnull(status,'')", DictConsts.STATUS_SUPPLIER_UNCONFIRM)
                .eq("ifnull(supplier_confirm_status,'')", DictConsts.STATUS_UNSUBMIT)
        ;
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        countInfo.setExtra(extra).setShow(1) .setValue(purchaseOrderService.count(queryWrapper));
        data.put("orderStartCount", countInfo);

        //待发货订单
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<Delivery>query()
                .eq("ifnull(status,'')", DictConsts.STATUS_DELIVERY_UNFILLED)
                .eq("ifnull(is_closed,'')", DictConsts.CLOSED_NO)
        ;
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        countInfo.setExtra(extra).setShow(1) .setValue(deliveryService.count(queryWrapper));
        data.put("deliveryStartCount", countInfo);

        //已完成订单
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<PurchaseOrder>query()
                .eq("ifnull(status,'')", DictConsts.STATUS_COMPLETE)
        ;
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        countInfo.setExtra(extra).setShow(1) .setValue(purchaseOrderService.count(queryWrapper));
        data.put("orderEndCount", countInfo);

        //资质过期
        countInfo = new CountInfoDTO(0);
        countInfo.setExtra(extra).setShow(1) .setValue(1);
        if (isSupplier) {
            countInfo.setValue(certificateRepositoryService.countForSupplier());
        }
        if (isHospital) {
            countInfo.setValue(certificateRepositoryService.countForHospital());
        }

        countInfo.setValue(certificateRepositoryService.countWarn());
        data.put("certExpireCount", countInfo);

        //已完成开票单金额
        countInfo = new CountInfoDTO(0);
        queryWrapper = Wrappers.<Invoice>query().select("sum(total_amount) as total_amount")
                .eq("ifnull(status,'')", DictConsts.STATUS_YES)
        ;
        if (isSupplier) {
            queryWrapper.eq(!isAll,"supplier_Id", supplierId);
        }
        if (isHospital) {
            queryWrapper.eq(!isAll,"hospital_id", hospitalId);
        }
        Invoice invoice = invoiceService.getOne(queryWrapper,false);
        countInfo.setExtra(extra).setShow(1).setValue(0);
        if (invoice != null && invoice.getTotalAmount() != null) {
            countInfo.setValue(invoice.getTotalAmount());
        }
        data.put("invoiceEndAmount", countInfo);

        return CommonResult.ok("查询成功", data);
    }

    /**
     * 待办任务
     *
     * @return
     */
    @GetMapping("/getTaskTodo")
    public CommonResult getTaskTodo() {
        List<TaskTodoDTO> todoList = new ArrayList<>();
        TaskTodoDTO todo;
        if (UserUtils.isSupplier()) {
            //订单待确认
            List<PurchaseOrder> orderList = purchaseOrderService.list(Wrappers.<PurchaseOrder>query()
                    .eq("supplier_Id", UserUtils.getSupplierId())
                    .eq("ifnull(status,'')", DictConsts.STATUS_SUPPLIER_UNCONFIRM)
                    .eq("ifnull(supplier_confirm_status,'')", DictConsts.STATUS_UNSUBMIT)
            );

            if (!orderList.isEmpty()) {
                for (PurchaseOrder item : orderList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCode()).setBusId(item.getId())
                            .setBusTypeName("采购订单").setBusType("order")
                            .setMenuRouteName("/order/indexConfirm").setRemark(item.getRemark())
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier()).setFlowStatusName("待确认")
                            .setFlowModified(item.getGmtAudited()).setFlowModifierName(item.getAuditorName()).setFlowStatus(item.getStatus());
                    todoList.add(todo);
                }
            }

            //待发货订单
            List<Delivery> deliveryList = deliveryService.list(Wrappers.<Delivery>query()
                    .eq("supplier_Id", UserUtils.getSupplierId())
                    .eq("ifnull(status,'')", DictConsts.STATUS_DELIVERY_UNFILLED)
                    .eq("ifnull(is_closed,'')", DictConsts.CLOSED_NO));

            if (!deliveryList.isEmpty()) {
                for (Delivery item : deliveryList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCode()).setBusId(item.getId())
                            .setBusTypeName("发货单").setBusType("order")
                            .setMenuRouteName("/delivery/indexAdd.vue").setRemark(item.getRemark())
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier()).setFlowStatusName("待发货")
                            .setFlowModified(item.getGmtAudited()).setFlowModifierName(item.getModifierName()).setFlowStatus(item.getStatus());
                    todoList.add(todo);
                }
            }

            //资质过期
            List<CertificateRepository> certWarnList = certificateRepositoryService.listWarn();
            if (!certWarnList.isEmpty()) {
                Date dateNow = DateUtils.now();
                int dayDiff = 0;

                for (CertificateRepository item : certWarnList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCertificateName()).setBusId(item.getId())
                            .setBusTypeName("资质预警").setBusType("certWarn")
                            .setMenuRouteName("/cert/sp_cert_crud_index.vue")
                            .setRemark(StrUtil.format("资质所属: {}, 效期: {}",item.getCertExtName(),DateUtils.format(item.getExpiryDate(),DateUtils.DEFAULT_PATTER_YMD)))
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier())
                            .setFlowModified(item.getGmtModified()).setFlowModifierName(item.getModifierName());
                    dayDiff = DateUtils.diffDate(dateNow,item.getExpiryDate());
                    if (dayDiff < 0) {
                        todo.setFlowStatusName("资质已过期");
                    } else {
                        todo.setFlowStatusName("资质不足30天");
                    }
                    todoList.add(todo);
                }
            }

            //待审核的开票单
            List<Invoice> invoiceList = invoiceService.list(
                    Wrappers.<Invoice>query()
                            .eq("supplier_Id", UserUtils.getSupplierId())
                            .ne("ifnull(status,'')", DictConsts.STATUS_YES)
            );

            if (!invoiceList.isEmpty()) {
                for (Invoice item : invoiceList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCode()).setBusId(item.getId())
                            .setBusTypeName("开票单").setBusType("order")
                            .setMenuRouteName("/settlement/invoice/audit_index.vue").setRemark(item.getRemark())
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier()).setFlowStatusName("待开票")
                            .setFlowModified(item.getGmtAudited()).setFlowModifierName(item.getModifierName()).setFlowStatus(item.getStatus());
                    todoList.add(todo);
                }
            }
        }

        if (UserUtils.isHospital()) {
            // 供方供货申请
            List<SupplierApplicant> supplierApplicantList = supplierApplicantService.list(Wrappers.<SupplierApplicant>query()
                    .eq("hospital_id",UserUtils.getHospitalId())
                    .eq("status",MaterialApplicant.STATUS_SUBMITED));
            if (!supplierApplicantList.isEmpty()) {
                for (SupplierApplicant item : supplierApplicantList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCode()).setBusId(item.getId())
                            .setBusTypeName("供方申请").setBusType("supplierApplicant")
                            .setMenuRouteName("/base/supplier/hp_apply/indexAudit.vue").setRemark(item.getRemark())
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier()).setFlowStatusName("待审核")
                            .setFlowModified(item.getGmtAudited()).setFlowModifierName(item.getModifierName()).setFlowStatus(item.getStatus());
                    todoList.add(todo);
                }
            }
            // 商品供货申请
            List<MaterialApplicant> materialApplicantList = materialApplicantService.list(Wrappers.<MaterialApplicant>query()
                    .eq("hospital_id",UserUtils.getHospitalId())
                    .eq("status",MaterialApplicant.STATUS_SUBMITED));
            if (!materialApplicantList.isEmpty()) {
                for (MaterialApplicant item : materialApplicantList) {
                    todo = new TaskTodoDTO();
                    todo.setBusKey(item.getCode()).setBusId(item.getId())
                            .setBusTypeName("供货申请").setBusType("materialApplicant")
                            .setMenuRouteName("/base/hospital_material/apply/indexAuditHp.vue").setRemark(item.getRemark())
                            .setGmtModified(item.getGmtModified()).setModifier(item.getModifier()).setFlowStatusName("待审核")
                            .setFlowModified(item.getGmtAudited()).setFlowModifierName(item.getModifierName()).setFlowStatus(item.getStatus());
                    todoList.add(todo);
                }
            }
        }

        if (!todoList.isEmpty()) {
            todoList.stream().filter(tmp -> StringUtils.isBlank(tmp.getFlowModifierName()))
                    .forEach(item -> {
                        item.setFlowModifierName(item.getModifier());
                    });
            todoList.stream().filter(tmp -> tmp.getFlowModified() == null && tmp.getGmtModified() != null)
                    .forEach(item -> {
                        item.setFlowModified(item.getGmtModified());
                    });

            List<String> codeList = todoList.stream().filter(tmp -> StringUtils.isNotBlank(tmp.getModifier())).map(TaskTodoDTO::getModifier).distinct().collect(Collectors.toList());
            codeList.addAll(todoList.stream().filter(tmp -> StringUtils.isNotBlank(tmp.getFlowModifierName())).map(TaskTodoDTO::getFlowModifierName).distinct().collect(Collectors.toList()));
            codeList = codeList.stream().distinct().collect(Collectors.toList());
            //填充修改人
            List<User> userList = userService.list(Wrappers.<User>query()
                    .in("login_key",codeList)
                    .or()
                    .in("id",codeList)
            );

            Map<String,User> userById = userList.stream().collect(Collectors.toMap(User::getId,item -> item));
            Map<String,User> userByLoginKey = userList.stream().collect(Collectors.toMap(User::getLoginKey,item -> item));
            todoList.stream().filter(tmp -> userById.containsKey(tmp.getFlowModifierName()) || userByLoginKey.containsKey(tmp.getFlowModifierName()))
                    .forEach(item -> {
                        if (userById.containsKey(item.getFlowModifierName())) {
                            item.setFlowModifierName(userById.get(item.getFlowModifierName()).getNickname());
                        }else if (userByLoginKey.containsKey(item.getFlowModifierName())) {
                            item.setFlowModifierName(userByLoginKey.get(item.getFlowModifierName()).getNickname());
                        }
                    });
        }
        return CommonResult.ok("查询成功", todoList);
    }


}
